package be.kuleuven.peno3.mobiletoledo.Data;

import android.content.Context;
import be.kuleuven.peno3.mobiletoledo.model.User;

/**
 * Class that manages settings which are stored locally.
 * 
 * @author s0213127
 *
 */
public class UserDAO extends LocalDAO{
   /**
     * Constructor - takes the context to allow the database to be
     * opened/created
     * 
     * @param ctx the Context within which to work
     */

    public UserDAO(Context ctx) {
		super(ctx);
	}


    
    public boolean readUserData() {
    	int numberOfSuccesses = 0;
		User user=User.getInstance();
		
		String username=fetchProperty("username");
		if(username!=null) {
			user.setUsername(username);
			numberOfSuccesses++;
		}
		
		String password=fetchProperty("password");
		if(password!=null) {
			user.setPassword(password);
			numberOfSuccesses++;
		}
		
		String userid=fetchProperty("userid");
		if(userid!=null) {
			user.setIdNumber(userid);
			numberOfSuccesses++;
		}
		
		String studyprogramme=fetchProperty("studyprogramme");
		if(studyprogramme!=null) {
			user.setStudyProgramme(studyprogramme);
			numberOfSuccesses++;
		}
		
		String group=fetchProperty("group");
		if(group!=null) {
			user.setGroup(group);
			numberOfSuccesses++;
		}
		
		String teacher=fetchProperty("teacher");
		if(teacher!=null) {
			if(teacher.equals("true")) {
				user.setTeacher(true);
			}
			else {
				user.setTeacher(false);
			}
			numberOfSuccesses++;
		}
		return (numberOfSuccesses==6);
	}
}
